#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[repr(C)]
pub struct Coordinate {
  pub column: i32,
  pub row: i32,
}

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[repr(C)]
pub struct Dimensions {
  pub width: i32,
  pub height: i32,
}

#[derive(Debug, Default, Clone, Copy)]
#[repr(C)]
pub struct CursesColorF32 {
  pub r: f32,
  pub g: f32,
  pub b: f32,
}

#[derive(Debug, Default, Clone, Copy)]
#[repr(C)]
pub struct ColorInfo {
  pub screenf: u8,
  pub screenb: u8,
  pub screenbright: bool,
  pub use_old_16_colors: bool,
  pub screen_color_r: u8,
  pub screen_color_g: u8,
  pub screen_color_b: u8,
  pub screen_color_br: u8,
  pub screen_color_bg: u8,
  pub screen_color_bb: u8,
  pub ccolor: [CursesColorF32; 16],
  pub uccolor: [Color; 16],
  pub color: [Color; 18],
}

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[repr(C)]
pub struct Color {
  pub r: u8,
  pub g: u8,
  pub b: u8,
}

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
#[repr(C)]
pub struct ColorPair {
  pub foreground: Color,
  pub background: Color,
}

impl From<ColorInfo> for ColorPair {
  fn from(color_info: ColorInfo) -> Self {
    let ColorInfo {
      use_old_16_colors,
      screenf: f,
      screenb: b,
      screenbright: bright,
      screen_color_r: fr,
      screen_color_g: fg,
      screen_color_b: fb,
      screen_color_br: br,
      screen_color_bg: bg,
      screen_color_bb: bb,
      ccolor: _,
      uccolor,
      color: _,
    } = color_info;

    if use_old_16_colors {
      let fg = (f + if bright { 8 } else { 0 }) as usize;
      let bg = (b + if bright { 8 } else { 0 }) as usize;
      ColorPair {
        foreground: uccolor[fg],
        background: uccolor[bg],
      }
    } else {
      ColorPair {
        foreground: Color { r: fr, g: fg, b: fb },
        background: Color { r: br, g: bg, b: bb },
      }
    }
  }
}
